<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">

        <div class="head-container">
          <!-- 搜索 -->
          <el-select v-model="query.type" class="filter-item" size="mini" style="margin-bottom: 10px;">
            <el-option v-for="item in dict.role_type" :key="item.id" :label="item.label" :value="item.value" />
          </el-select>

          <rrOperation />
        </div>
      </div>
      <crudOperation :permission="permission" />
    </div>
    <!--表单组件-->
    <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="470px">
      <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
        <el-form-item label="比例类型" prop="type">
          <el-select v-model="form.type" style="width: 100%;">
            <el-option v-for="item in dict.role_type" :key="item.id" :label="item.label" :value="+item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="佣金比例" prop="proportion">
          <el-input-number v-model="form.proportion" controls-position="right" style="width: 100%;" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="text" @click="crud.cancelCU">取消</el-button>
        <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
      </div>
    </el-dialog>
    <!--表格渲染-->
    <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%" @selection-change="crud.selectionChangeHandler">
      <el-table-column type="selection" width="55" />
      <el-table-column prop="type" label="佣金比例类型">
        <template slot-scope="scope">
          <span>{{ selectDictLabel(dict.role_type,scope.row.type) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="proportion" label="佣金比例" />
      <el-table-column v-if="checkPer(['admin','serverDeploy:edit','serverDeploy:del'])" label="操作" width="150px" align="center">
        <template slot-scope="scope">
          <udOperation
            :data="scope.row"
            :permission="permission"
          />
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>

<script>

import crudProportion from '@/api/mini/commission'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
const defaultForm = { type: '', proportion: '' }
export default {
  name: 'Commission',
  dicts: ['role_type'],
  components: { pagination, crudOperation, rrOperation, udOperation },
  cruds() {
    return CRUD({ title: '佣金比例', url: '/api/proportion/list', listKey: ['data'], crudMethod: { ...crudProportion }})
  },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  data() {
    return {
      accountList: [],
      accountMap: {},
      loading: false,
      permission: {
        add: ['admin', 'proportion:add'],
        edit: ['admin', 'proportion:edit'],
        del: ['admin', 'proportion:del']
      },
      rules: {
        type: [
          { required: true, message: '请选择佣金类型', trigger: 'blur' }
        ],
        proportion: [
          { required: true, message: '请输入佣金比例', trigger: 'blur', type: 'number' }
        ]
      }
    }
  }
}
</script>

  <style rel="stylesheet/scss" lang="scss" scoped>
   ::v-deep .el-input-number .el-input__inner {
      text-align: left;
    }
  </style>
